package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.PKnowledge;
import com.ruoyi.system.service.IPKnowledgeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 维修知识Controller
 * 
 * @author ruoyi
 * @date 2024-03-23
 */
@RestController
@RequestMapping("/knowledge")
public class PKnowledgeController extends BaseController
{
    @Autowired
    private IPKnowledgeService pKnowledgeService;

    /**
     * 查询维修知识列表
     */
    @RequiresPermissions("system:knowledge:list")
    @GetMapping("/list")
    public TableDataInfo list(PKnowledge pKnowledge)
    {
        startPage();
        List<PKnowledge> list = pKnowledgeService.selectPKnowledgeList(pKnowledge);
        return getDataTable(list);
    }

    /**
     * 导出维修知识列表
     */
    @RequiresPermissions("system:knowledge:export")
    @Log(title = "维修知识", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PKnowledge pKnowledge)
    {
        List<PKnowledge> list = pKnowledgeService.selectPKnowledgeList(pKnowledge);
        ExcelUtil<PKnowledge> util = new ExcelUtil<PKnowledge>(PKnowledge.class);
        util.exportExcel(response, list, "维修知识数据");
    }

    /**
     * 获取维修知识详细信息
     */
    @RequiresPermissions("system:knowledge:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pKnowledgeService.selectPKnowledgeById(id));
    }

    /**
     * 新增维修知识
     */
    @RequiresPermissions("system:knowledge:add")
    @Log(title = "维修知识", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PKnowledge pKnowledge)
    {
        return toAjax(pKnowledgeService.insertPKnowledge(pKnowledge));
    }

    /**
     * 修改维修知识
     */
    @RequiresPermissions("system:knowledge:edit")
    @Log(title = "维修知识", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PKnowledge pKnowledge)
    {
        return toAjax(pKnowledgeService.updatePKnowledge(pKnowledge));
    }

    /**
     * 删除维修知识
     */
    @RequiresPermissions("system:knowledge:remove")
    @Log(title = "维修知识", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pKnowledgeService.deletePKnowledgeByIds(ids));
    }
}
